#include <iostream>
#include "DBSCAN.h"
using namespace std;
/***************************************全局变量***************************************/
Lidar Lidar_init;
/***************************************DBSCAN***************************************/
vector<Lidar_Point> Lidar_data;
vector<Lidar_Point> Lidar_class_data;

// 查找给定数据点的邻居   ==>遍历除自身外的所有点，计算与该点的距离
//                                             数据      第几个点         距离阈值
vector<int> findNeighbors(const vector<Lidar_Point> &data, int pointIdx, double epsilon, int range, vector<int> &isvalid)
{
    vector<int> neighbors;
    const Lidar_Point &target = data[pointIdx];
    const int dataSize = static_cast<int>(data.size());
    for (int i = -range; i <= range; ++i)
    {
        if (i == 0) // 跳过自身
            continue;

        int neighborIdx = (pointIdx + i + dataSize) % dataSize; // 考虑环形结构
        if (isvalid[neighborIdx] == 1)
            continue;
        const Lidar_Point &current = data[neighborIdx];
        double distance = Euclidean_distance(target, current);

        // 在阈值范围内则添加到邻居列表
        if (distance <= epsilon)
        {
            neighbors.push_back(neighborIdx);
        }
    }

    return neighbors;
}

// vector<int> findNeighbors(const vector<Lidar_Point> &data, int pointIdx, double epsilon)
// {
//     vector<int> neighbors;
//     const Lidar_Point &target = data[pointIdx];
//     for (int i = 0; i < data.size(); ++i)
//     {
//         if (i == pointIdx)
//             continue;
//         const Lidar_Point &current = data[i];
//         double distance = Euclidean_distance(target, current);
//         if (distance <= epsilon)
//         {
//             neighbors.push_back(i);
//         }
//     }
//     return neighbors; // 领域的点
// }